home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / StyleConstants.java < prev    next >
Text File  |  1998-06-30  |  24KB  |  872 lines

  1. /*
  2.  * @(#)StyleConstants.java    1.18 98/04/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.text;
  21.  
  22. import java.awt.Color;
  23. import java.awt.Component;
  24. import com.sun.java.swing.Icon;
  25.  
  26. /**
  27.  * <p>
  28.  * A collection of <em>well known</em> or common attribute keys
  29.  * and methods to apply to an AttributeSet or MutableAttributeSet
  30.  * to get/set the properties in a typesafe manner.  
  31.  * <p>
  32.  * The paragraph attributes form the definition of a paragraph to be rendered.
  33.  * All sizes are specified in points (such as found in postscript), a
  34.  * device independent measure.
  35.  * </p>
  36.  * <p align=center><img src="doc-files/paragraph.gif"></p>
  37.  * <p>
  38.  * 
  39.  * @author  Timothy Prinzing
  40.  * @version 1.18 04/09/98
  41.  */
  42. public class StyleConstants {
  43.  
  44.     /**
  45.      * Name of elements used to represent components.
  46.      */
  47.     public static final String ComponentElementName = "component";
  48.     
  49.     /**
  50.      * Name of elements used to represent icons.
  51.      */
  52.     public static final String IconElementName = "icon";
  53.  
  54.     /**
  55.      * Attribute name used to name the collection of
  56.      * attributes.
  57.      */
  58.     public static final Object NameAttribute = new StyleConstants("name");
  59.  
  60.     /**
  61.      * Attribute name used to identifiy the resolving parent
  62.      * set of attributes, if one is defined.
  63.      */
  64.     public static final Object ResolveAttribute = new StyleConstants("resolver");
  65.  
  66.     /**
  67.      * Returns the string representation.
  68.      *
  69.      * @return the string
  70.      */
  71.     public String toString() {
  72.         return representation;
  73.     }
  74.  
  75.     // ---- character constants -----------------------------------
  76.  
  77.     /**
  78.      * Name of the font family.
  79.      */
  80.     public static final Object FontFamily = CharacterConstants.Family;
  81.  
  82.     /**
  83.      * Name of the font size.
  84.      */
  85.     public static final Object FontSize = CharacterConstants.Size;
  86.  
  87.     /**
  88.      * Name of the bold attribute.
  89.      */
  90.     public static final Object Bold = CharacterConstants.Bold;
  91.  
  92.     /**
  93.      * Name of the italic attribute.
  94.      */
  95.     public static final Object Italic = CharacterConstants.Italic;
  96.  
  97.     /**
  98.      * Name of the underline attribute.
  99.      */
  100.     public static final Object Underline = CharacterConstants.Underline;
  101.  
  102.     /**
  103.      * Name of the foreground color attribute.
  104.      */
  105.     public static final Object Foreground = CharacterConstants.Foreground;
  106.  
  107.     /**
  108.      * Name of the background color attribute.
  109.      */
  110.     public static final Object Background = CharacterConstants.Background;
  111.  
  112.     /**
  113.      * Name of the component attribute.
  114.      */
  115.     public static final Object ComponentAttribute = CharacterConstants.ComponentAttribute;
  116.  
  117.     /**
  118.      * Name of the icon attribute.
  119.      */
  120.     public static final Object IconAttribute = CharacterConstants.IconAttribute;
  121.  
  122.     /**
  123.      * The amount of space to indent the first
  124.      * line of the paragraph.  This value may be negative
  125.      * to offset in the reverse direction.  The type
  126.      * is Float and specifies the size of the space
  127.      * in points.
  128.      */
  129.     public static final Object FirstLineIndent = ParagraphConstants.FirstLineIndent;
  130.  
  131.     /**
  132.      * The amount to indent the left side
  133.      * of the paragraph.
  134.      * Type is float and specifies the size in points.
  135.      */
  136.     public static final Object LeftIndent = ParagraphConstants.LeftIndent;
  137.  
  138.     /**
  139.      * The amount to indent the right side
  140.      * of the paragraph.
  141.      * Type is float and specifies the size in points.
  142.      */
  143.     public static final Object RightIndent = ParagraphConstants.RightIndent;
  144.  
  145.     /**
  146.      * The amount of space between lines
  147.      * of the paragraph.
  148.      * Type is float and specifies the size in points.
  149.      */
  150.     public static final Object LineSpacing = ParagraphConstants.LineSpacing;
  151.  
  152.     /**
  153.      * The amount of space above the paragraph.
  154.      * Type is float and specifies the size in points.
  155.      */
  156.     public static final Object SpaceAbove = ParagraphConstants.SpaceAbove;
  157.  
  158.     /**
  159.      * The amount of space below the paragraph.
  160.      * Type is float and specifies the size in points.
  161.      */
  162.     public static final Object SpaceBelow = ParagraphConstants.SpaceBelow;
  163.  
  164.     /**
  165.      * Alignment for the paragraph.  The type is
  166.      * Integer.  Valid values are:
  167.      * <ul>
  168.      * <li>ALIGN_LEFT
  169.      * <li>ALIGN_RIGHT
  170.      * <li>ALIGN_CENTER
  171.      * <li>ALIGN_JUSTIFED
  172.      * </ul>
  173.      *
  174.      */
  175.     public static final Object Alignment = ParagraphConstants.Alignment;
  176.  
  177.     /**
  178.      * TabSet for the paragraph, type is a TabSet containing
  179.      * TabStops.
  180.      */
  181.     public static final Object TabSet = ParagraphConstants.TabSet;
  182.  
  183.     /**
  184.      * A possible value for paragraph alignment.  This
  185.      * specifies that the text is aligned to the left 
  186.      * indent and extra whitespace should be placed on
  187.      * the right.
  188.      */
  189.     public static final int ALIGN_LEFT = 0;
  190.  
  191.     /**
  192.      * A possible value for paragraph alignment.  This
  193.      * specifies that the text is aligned to the center
  194.      * and extra whitespace should be placed equally on
  195.      * the left and right.
  196.      */
  197.     public static final int ALIGN_CENTER = 1;
  198.  
  199.     /**
  200.      * A possible value for paragraph alignment.  This
  201.      * specifies that the text is aligned to the right
  202.      * indent and extra whitespace should be placed on
  203.      * the left.
  204.      */
  205.     public static final int ALIGN_RIGHT = 2;
  206.  
  207.     /**
  208.      * A possible value for paragraph alignment.  This
  209.      * specifies that extra whitespace should be spread
  210.      * out through the rows of the paragraph with the
  211.      * text lined up with the left and right indent
  212.      * except on the last line which should be aligned
  213.      * to the left.
  214.      */
  215.     public static final int ALIGN_JUSTIFIED = 3;
  216.  
  217.     // --- character attribute accessors ---------------------------
  218.  
  219.     /**
  220.      * Gets the component setting from the attribute list.
  221.      *
  222.      * @param a the attribute set
  223.      * @return the component, null if none
  224.      */
  225.     public static Component getComponent(AttributeSet a) {
  226.         return (Component) a.getAttribute(ComponentAttribute);
  227.     }
  228.  
  229.     /**
  230.      * Sets the component attribute.
  231.      *
  232.      * @param a the attribute set
  233.      * @param c the component
  234.      */
  235.     public static void setComponent(MutableAttributeSet a, Component c) {
  236.         a.addAttribute(AbstractDocument.ElementNameAttribute, ComponentElementName);
  237.         a.addAttribute(ComponentAttribute, c);
  238.     }
  239.  
  240.     /**
  241.      * Gets the icon setting from the attribute list.
  242.      *
  243.      * @param a the attribute set
  244.      * @return the icon, null if none
  245.      */
  246.     public static Icon getIcon(AttributeSet a) {
  247.         return (Icon) a.getAttribute(IconAttribute);
  248.     }
  249.  
  250.     /**
  251.      * Sets the icon attribute.
  252.      *
  253.      * @param a the attribute set
  254.      * @param c the icon
  255.      */
  256.     public static void setIcon(MutableAttributeSet a, Icon c) {
  257.         a.addAttribute(AbstractDocument.ElementNameAttribute, IconElementName);
  258.         a.addAttribute(IconAttribute, c);
  259.     }
  260.  
  261.     /**
  262.      * Gets the font family setting from the attribute list.
  263.      *
  264.      * @param a the attribute set
  265.      * @return the font family, "Monospaced" as the default
  266.      */
  267.     public static String getFontFamily(AttributeSet a) {
  268.         String family = (String) a.getAttribute(FontFamily);
  269.         if (family == null) {
  270.             family = "Monospaced";
  271.         }
  272.         return family;
  273.     }
  274.  
  275.     /**
  276.      * Sets the font attribute.
  277.      *
  278.      * @param a the attribute set
  279.      * @param fam the font
  280.      */
  281.     public static void setFontFamily(MutableAttributeSet a, String fam) {
  282.         a.addAttribute(FontFamily, fam);
  283.     }
  284.  
  285.     /**
  286.      * Gets the font size setting from the attribute list.
  287.      *
  288.      * @param a the attribute set
  289.      * @return the font size, 12 as the default
  290.      */
  291.     public static int getFontSize(AttributeSet a) {
  292.         Integer size = (Integer) a.getAttribute(FontSize);
  293.         if (size != null) {
  294.             return size.intValue();
  295.         }
  296.         return 12;
  297.     }
  298.  
  299.     /**
  300.      * Sets the font size attribute.
  301.      *
  302.      * @param a the attribute set
  303.      * @param s the font size 
  304.      */
  305.     public static void setFontSize(MutableAttributeSet a, int s) {
  306.         a.addAttribute(FontSize, new Integer(s));
  307.     }
  308.  
  309.     /**
  310.      * Checks whether the bold attribute is set.
  311.      *
  312.      * @param a the attribute set
  313.      * @return true if set else false
  314.      */
  315.     public static boolean isBold(AttributeSet a) {
  316.         Boolean bold = (Boolean) a.getAttribute(Bold);
  317.         if (bold != null) {
  318.             return bold.booleanValue();
  319.         }
  320.         return false;
  321.     }
  322.  
  323.     /**
  324.      * Sets the bold attribute.
  325.      *
  326.      * @param a the attribute set
  327.      * @param b specifies true/false for setting the attribute
  328.      */
  329.     public static void setBold(MutableAttributeSet a, boolean b) {
  330.         a.addAttribute(Bold, new Boolean(b));
  331.     }
  332.  
  333.     /**
  334.      * Checks whether the italic attribute is set.
  335.      *
  336.      * @param a the attribute set
  337.      * @return true if set else false
  338.      */
  339.     public static boolean isItalic(AttributeSet a) {
  340.         Boolean italic = (Boolean) a.getAttribute(Italic);
  341.         if (italic != null) {
  342.             return italic.booleanValue();
  343.         }
  344.         return false;
  345.     }
  346.  
  347.     /**
  348.      * Sets the italic attribute.
  349.      *
  350.      * @param a the attribute set
  351.      * @param b specifies true/false for setting the attribute
  352.      */
  353.     public static void setItalic(MutableAttributeSet a, boolean b) {
  354.         a.addAttribute(Italic, new Boolean(b));
  355.     }
  356.  
  357.     /**
  358.      * Checks whether the underline attribute is set.
  359.      *
  360.      * @param a the attribute set
  361.      * @return true if set else false
  362.      */
  363.     public static boolean isUnderline(AttributeSet a) {
  364.         Boolean underline = (Boolean) a.getAttribute(Underline);
  365.         if (underline != null) {
  366.             return underline.booleanValue();
  367.         }
  368.         return false;
  369.     }
  370.  
  371.     /**
  372.      * Sets the underline attribute.
  373.      *
  374.      * @param a the attribute set
  375.      * @param b specifies true/false for setting the attribute
  376.      */
  377.     public static void setUnderline(MutableAttributeSet a, boolean b) {
  378.         a.addAttribute(Underline, new Boolean(b));
  379.     }
  380.  
  381.     /**
  382.      * Gets the foreground color setting from the attribute list.
  383.      *
  384.      * @param a the attribute set
  385.      * @return the color, Color.black as the default
  386.      */
  387.     public static Color getForeground(AttributeSet a) {
  388.         Color fg = (Color) a.getAttribute(Foreground);
  389.         if (fg == null) {
  390.             fg = Color.black;
  391.         }
  392.         return fg;
  393.     }
  394.  
  395.     /**
  396.      * Sets the foreground color.
  397.      *
  398.      * @param a the attribute set
  399.      * @param fg the color
  400.      */
  401.     public static void setForeground(MutableAttributeSet a, Color fg) {
  402.         a.addAttribute(Foreground, fg);
  403.     }
  404.  
  405.  
  406.     // --- paragraph attribute accessors ----------------------------
  407.  
  408.     /**
  409.      * Gets the first line indent setting.
  410.      *
  411.      * @param a the attribute set
  412.      * @returns the value, 0 if not set
  413.      */
  414.     public static float getFirstLineIndent(AttributeSet a) {
  415.         Float indent = (Float) a.getAttribute(FirstLineIndent);
  416.         if (indent != null) {
  417.             return indent.floatValue();
  418.         }
  419.         return 0;
  420.     }
  421.     
  422.     /**
  423.      * Sets the first line indent.
  424.      *
  425.      * @param a the attribute set
  426.      * @param i the value
  427.      */ 
  428.     public static void setFirstLineIndent(MutableAttributeSet a, float i) {
  429.         a.addAttribute(FirstLineIndent, new Float(i));
  430.     }
  431.  
  432.     /**
  433.      * Gets the right indent setting.
  434.      *
  435.      * @param a the attribute set
  436.      * @returns the value, 0 if not set
  437.      */
  438.     public static float getRightIndent(AttributeSet a) {
  439.         Float indent = (Float) a.getAttribute(RightIndent);
  440.         if (indent != null) {
  441.             return indent.floatValue();
  442.         }
  443.         return 0;
  444.     }
  445.  
  446.     /**
  447.      * Sets right indent.
  448.      *
  449.      * @param a the attribute set
  450.      * @param i the value
  451.      */ 
  452.     public static void setRightIndent(MutableAttributeSet a, float i) {
  453.         a.addAttribute(RightIndent, new Float(i));
  454.     }
  455.  
  456.     /**
  457.      * Gets the left indent setting.
  458.      *
  459.      * @param a the attribute set
  460.      * @returns the value, 0 if not set
  461.      */
  462.     public static float getLeftIndent(AttributeSet a) {
  463.         Float indent = (Float) a.getAttribute(LeftIndent);
  464.         if (indent != null) {
  465.             return indent.floatValue();
  466.         }
  467.         return 0;
  468.     }
  469.  
  470.     /**
  471.      * Sets left indent.
  472.      *
  473.      * @param a the attribute set
  474.      * @param i the value
  475.      */ 
  476.     public static void setLeftIndent(MutableAttributeSet a, float i) {
  477.         a.addAttribute(LeftIndent, new Float(i));
  478.     }
  479.  
  480.     /**
  481.      * Gets the line spacing setting.
  482.      *
  483.      * @param a the attribute set
  484.      * @returns the value, 0 if not set
  485.      */
  486.     public static float getLineSpacing(AttributeSet a) {
  487.         Float space = (Float) a.getAttribute(LineSpacing);
  488.         if (space != null) {
  489.             return space.floatValue();
  490.         }
  491.         return 0;
  492.     }
  493.  
  494.     /**
  495.      * Sets line spacing.
  496.      *
  497.      * @param a the attribute set
  498.      * @param i the value
  499.      */ 
  500.     public static void setLineSpacing(MutableAttributeSet a, float i) {
  501.         a.addAttribute(LineSpacing, new Float(i));
  502.     }
  503.  
  504.     /**
  505.      * Gets the space above setting.
  506.      *
  507.      * @param a the attribute set
  508.      * @returns the value, 0 if not set
  509.      */
  510.     public static float getSpaceAbove(AttributeSet a) {
  511.         Float space = (Float) a.getAttribute(SpaceAbove);
  512.         if (space != null) {
  513.             return space.floatValue();
  514.         }
  515.         return 0;
  516.     }
  517.  
  518.     /**
  519.      * Sets space above.
  520.      *
  521.      * @param a the attribute set
  522.      * @param i the value
  523.      */ 
  524.     public static void setSpaceAbove(MutableAttributeSet a, float i) {
  525.         a.addAttribute(SpaceAbove, new Float(i));
  526.     }
  527.  
  528.     /**
  529.      * Gets the space below setting.
  530.      *
  531.      * @param a the attribute set
  532.      * @returns the value, 0 if not set
  533.      */
  534.     public static float getSpaceBelow(AttributeSet a) {
  535.         Float space = (Float) a.getAttribute(SpaceBelow);
  536.         if (space != null) {
  537.             return space.floatValue();
  538.         }
  539.         return 0;
  540.     }
  541.  
  542.     /**
  543.      * Sets space below.
  544.      *
  545.      * @param a the attribute set
  546.      * @param i the value
  547.      */ 
  548.     public static void setSpaceBelow(MutableAttributeSet a, float i) {
  549.         a.addAttribute(SpaceBelow, new Float(i));
  550.     }
  551.  
  552.     /**
  553.      * Gets the alignment setting.
  554.      *
  555.      * @param a the attribute set
  556.      * @returns the value, StyleConstants.ALIGN_LEFT if not set
  557.      */
  558.     public static int getAlignment(AttributeSet a) {
  559.         Integer align = (Integer) a.getAttribute(Alignment);
  560.         if (align != null) {
  561.             return align.intValue();
  562.         }
  563.         return ALIGN_LEFT;
  564.     }
  565.     
  566.     /**
  567.      * Sets alignment.
  568.      *
  569.      * @param a the attribute set
  570.      * @param align the alignment value
  571.      */ 
  572.     public static void setAlignment(MutableAttributeSet a, int align) {
  573.         a.addAttribute(Alignment, new Integer(align));
  574.     }
  575.  
  576.     /**
  577.      * Gets the TabSet.
  578.      *
  579.      * @param a the attribute set
  580.      * @returns the TabSet.
  581.      */
  582.     public static TabSet getTabSet(AttributeSet a) {
  583.         TabSet tabs = (TabSet)a.getAttribute(TabSet);
  584.         // PENDING: should this return a default?
  585.         return tabs;
  586.     }
  587.  
  588.     /**
  589.      * Sets the TabSet.
  590.      *
  591.      * @param a the attribute set.
  592.      * @param tabs the TabSet
  593.      */
  594.     public static void setTabSet(MutableAttributeSet a, TabSet tabs) {
  595.         a.addAttribute(TabSet, tabs);
  596.     }
  597.  
  598.     // --- privates ---------------------------------------------
  599.  
  600.     private static Object[] keys = { 
  601.         NameAttribute, ResolveAttribute, 
  602.         FontFamily, FontSize, Bold, Italic, Underline, 
  603.         Foreground, Background, ComponentAttribute,
  604.         IconAttribute, FirstLineIndent, LeftIndent,
  605.         RightIndent, LineSpacing, SpaceAbove, SpaceBelow,
  606.         Alignment, TabSet
  607.     };
  608.  
  609.     static {
  610.         try {
  611.             for (int i = 0; i < keys.length; i++) {
  612.                 StyleContext.registerStaticAttributeKey(keys[i]);
  613.             }
  614.         } catch (Throwable e) {
  615.             e.printStackTrace();
  616.         }
  617.     }
  618.  
  619.     private StyleConstants(String representation) {
  620.         this.representation = representation;
  621.     }
  622.  
  623.     private String representation;
  624.  
  625.     /**
  626.      * This is a typesafe enumeration of the <em>well-known</em> 
  627.      * attributes that contribute to a paragraph style.  These are 
  628.      * aliased by the outer class for general presentation.
  629.      */
  630.     public static class ParagraphConstants implements AttributeSet.ParagraphAttribute {
  631.  
  632.         /**
  633.          * The amount of space to indent the first
  634.          * line of the paragraph.  This value may be negative
  635.          * to offset in the reverse direction.  The type
  636.          * is Float and specifies the size of the space
  637.          * in points.
  638.          */
  639.         public static final Object FirstLineIndent = new ParagraphConstants("FirstLineIndent");
  640.  
  641.         /**
  642.          * The amount to indent the left side
  643.          * of the paragraph.
  644.          * Type is float and specifies the size in points.
  645.          */
  646.         public static final Object LeftIndent = new ParagraphConstants("LeftIndent");
  647.  
  648.         /**
  649.          * The amount to indent the right side
  650.          * of the paragraph.
  651.          * Type is float and specifies the size in points.
  652.          */
  653.         public static final Object RightIndent = new ParagraphConstants("RightIndent");
  654.  
  655.         /**
  656.          * The amount of space between lines
  657.          * of the paragraph.
  658.          * Type is float and specifies the size in points.
  659.          */
  660.         public static final Object LineSpacing = new ParagraphConstants("LineSpacing");
  661.  
  662.         /**
  663.          * The amount of space above the paragraph.
  664.          * Type is float and specifies the size in points.
  665.          */
  666.         public static final Object SpaceAbove = new ParagraphConstants("SpaceAbove");
  667.  
  668.         /**
  669.          * The amount of space below the paragraph.
  670.          * Type is float and specifies the size in points.
  671.          */
  672.         public static final Object SpaceBelow = new ParagraphConstants("SpaceBelow");
  673.  
  674.         /**
  675.          * Alignment for the paragraph.  The type is
  676.          * Integer.  Valid values are:
  677.          * <ul>
  678.          * <li>ALIGN_LEFT
  679.          * <li>ALIGN_RIGHT
  680.          * <li>ALIGN_CENTER
  681.          * <li>ALIGN_JUSTIFED
  682.          * </ul>
  683.          *
  684.          */
  685.         public static final Object Alignment = new ParagraphConstants("Alignment");
  686.  
  687.         /**
  688.          * TabSet for the paragraph.
  689.          */
  690.         public static final Object TabSet = new ParagraphConstants("TabSet");
  691.  
  692.         /**
  693.          * Returns the string representation.
  694.          *
  695.          * @return the string
  696.          */
  697.         public String toString() {
  698.             return representation;
  699.         }
  700.  
  701.         // --- privates ---------------------------------------------
  702.  
  703.         private ParagraphConstants(String representation) {
  704.             this.representation = representation;
  705.         }
  706.  
  707.         private String representation;
  708.  
  709.     }
  710.  
  711.     /**
  712.      * This is a typesafe enumeration of the <em>well-known</em> 
  713.      * attributes that contribute to a character style.  These are 
  714.      * aliased by the outer class for general presentation.
  715.      */
  716.     public static class CharacterConstants implements AttributeSet.CharacterAttribute {
  717.  
  718.         /**
  719.          * Name of the underline attribute.
  720.          */
  721.         public static final Object Underline = new CharacterConstants("underline");
  722.  
  723.         /**
  724.          * Name of the component attribute.
  725.          */
  726.         public static final Object ComponentAttribute = new CharacterConstants("component");
  727.  
  728.         /**
  729.          * Name of the icon attribute.
  730.          */
  731.         public static final Object IconAttribute = new CharacterConstants("icon");
  732.  
  733.     /**
  734.      * Orientation of visual text flow for the purpose of Bidi.
  735.      */
  736.     public static final Object Orientation = new CharacterConstants("orientation");
  737.  
  738.         /**
  739.          * Name of the font family.
  740.          */
  741.         public static final Object Family = FontConstants.Family;
  742.  
  743.         /**
  744.          * Name of the font size.
  745.          */
  746.         public static final Object Size = FontConstants.Size;
  747.  
  748.         /**
  749.          * Name of the bold attribute.
  750.          */ 
  751.         public static final Object Bold = FontConstants.Bold;
  752.  
  753.         /**
  754.          * Name of the italic attribute.
  755.          */
  756.         public static final Object Italic = FontConstants.Italic;
  757.  
  758.         /**
  759.          * Name of the foreground color attribute.
  760.          */
  761.         public static final Object Foreground = ColorConstants.Foreground;
  762.  
  763.         /**
  764.          * Name of the background color attribute.
  765.          */
  766.         public static final Object Background = ColorConstants.Background;
  767.  
  768.         /**
  769.          * Returns the string representation.
  770.          *
  771.          * @return the string
  772.          */
  773.         public String toString() {
  774.             return representation;
  775.         }
  776.  
  777.         // --- privates ---------------------------------------------
  778.  
  779.         private CharacterConstants(String representation) {
  780.             this.representation = representation;
  781.         }
  782.  
  783.         private String representation;
  784.  
  785.     }
  786.  
  787.     /**
  788.      * This is a typesafe enumeration of the <em>well-known</em> 
  789.      * attributes that contribute to a color.  These are aliased
  790.      * by the outer class for general presentation.
  791.      */
  792.     public static class ColorConstants implements 
  793.         AttributeSet.ColorAttribute,  AttributeSet.CharacterAttribute {
  794.  
  795.         /**
  796.          * Name of the foreground color attribute.
  797.          */
  798.         public static final Object Foreground = new ColorConstants("foreground");
  799.  
  800.         /**
  801.          * Name of the background color attribute.
  802.          */
  803.         public static final Object Background = new ColorConstants("background");
  804.  
  805.         /**
  806.          * Returns the string representation.
  807.          *
  808.          * @return the string
  809.          */
  810.         public String toString() {
  811.             return representation;
  812.         }
  813.  
  814.         // --- privates ---------------------------------------------
  815.  
  816.         private ColorConstants(String representation) {
  817.             this.representation = representation;
  818.         }
  819.  
  820.         private String representation;
  821.  
  822.     }
  823.  
  824.     /**
  825.      * This is a typesafe enumeration of the <em>well-known</em> 
  826.      * attributes that contribute to a font.  These are aliased
  827.      * by the outer class for general presentation.
  828.      */
  829.     public static class FontConstants implements 
  830.         AttributeSet.FontAttribute, AttributeSet.CharacterAttribute {
  831.  
  832.         /**
  833.          * Name of the font family.
  834.          */
  835.         public static final Object Family = new FontConstants("family");
  836.  
  837.         /**
  838.          * Name of the font size.
  839.          */
  840.         public static final Object Size = new FontConstants("size");
  841.  
  842.         /**
  843.          * Name of the bold attribute.
  844.          */ 
  845.         public static final Object Bold = new FontConstants("bold");
  846.  
  847.         /**
  848.          * Name of the italic attribute.
  849.          */
  850.         public static final Object Italic = new FontConstants("italic");
  851.  
  852.         /**
  853.          * Returns the string representation.
  854.          *
  855.          * @return the string
  856.          */
  857.         public String toString() {
  858.             return representation;
  859.         }
  860.  
  861.         // --- privates ---------------------------------------------
  862.  
  863.         private FontConstants(String representation) {
  864.             this.representation = representation;
  865.         }
  866.  
  867.         private String representation;
  868.  
  869.     }
  870.  
  871. }
  872.